package cn.edu.gsau.info.dao;

import cn.edu.gsau.info.models.Jiaocaizhuanzhu;
import cn.edu.gsau.info.models.Shenhe;
import cn.edu.gsau.info.models.Zhengmingcailiao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jinjiang
 * @since 2022-11-17
 */
public interface JiaocaizhuanzhuDao extends BaseMapper<Jiaocaizhuanzhu> {
    @Select("SELECT id,tianbaoId,tianbaoName,bookName,chuBanSeh," +
            "chuBanDate,AUTHORS,zongRenShu,meSort,createBy,createTime,updateBy,updateTime,STATUS,node,manager,deleted,memo " +
            "FROM tbl_jiaocaizhuanzhu WHERE tianbaoId IN ("+"#{tianbaoid}"+") AND deleted=0")
    public List<Jiaocaizhuanzhu> findByTianbaoId(Long tianbaoid);


    @Select("SELECT fileName FROM tbl_zhengmingcailiao WHERE moduleId = #{modeleId}} AND recoreId = #{recoreId}")
    public List<Zhengmingcailiao> findByModuleIdAndRecoreId(Integer moduleId,long recoreId);

    @Select("SELECT * FROM tbl_jiaocaizhuanzhu WHERE tianbaoId = #{tianbaoid} AND `status` = #{status} AND deleted = 0" )
    public List<Jiaocaizhuanzhu> findByTianbaoIdAndStatus(long tianbaoid,String status);

    @Select("SELECT * FROM tbl_jiaocaizhuanzhu WHERE tianbaoId = #{tianbaoid} AND bookName LIKE "+"CONCAT('%',#{keyword},'%') AND deleted = 0")
    public List<Jiaocaizhuanzhu> findByTianbaoIdAndKeyWord(long tianbaoid,String keyword);

    @Select("SELECT * FROM tbl_jiaocaizhuanzhu WHERE tianbaoId = #{tianbaoid} AND bookName LIKE "+"CONCAT('%',#{keyword},'%') AND `status` = #{status} AND deleted = 0")
    public List<Jiaocaizhuanzhu> findByTianbaoIdAndKeyWordAndStatus(long tianbaoid,String keyword,String status);

    @Update("UPDATE tbl_zhengmingcailiao SET recoreId = #{id} WHERE fileFullPath LIKE "+"CONCAT('%',#{fileName},'%')")
    public Boolean updateRecoreId(String fileName,long id);

    @Select("SELECT * FROM tbl_zhengmingcailiao WHERE recoreId = #{recoreId} AND moduleId = #{moduleId}")
    public List<Zhengmingcailiao> findfileByrecoreIdAndModuleId(long recoreId,long moduleId);

    @Delete("DELETE FROM tbl_zhengmingcailiao WHERE id = #{id}")
    public Boolean deleteCailiao(long id);

    @Insert("INSERT INTO tbl_zhengmingcailiao VALUES(#{id},#{moduleId},#{recoreID},#{fileName},#{fileFullPath},#{memo})")
    public Boolean addCailiao(long id ,int moduleId, long recoreId,String fileName , String fileFullPath , String memo);

    @Select("SELECT * FROM tbl_shenhe WHERE moduleId = #{moduleId} AND tijiaoId = #{tijiaoId} AND memo = 0")
    public List<Shenhe> findallshenhe(int moduleId,long tijiaoId);

    @Select("SELECT * FROM tbl_jiaocaizhuanzhu WHERE node = #{node} AND deleted=0")
    public List<Jiaocaizhuanzhu> findByNode(String node);

    @Select("SELECT * FROM tbl_jiaocaizhuanzhu WHERE bookName LIKE "+"CONCAT('%',#{keyword},'%') AND node = #{node} AND deleted=0")
    public List<Jiaocaizhuanzhu> searchByNode(String keyword,String node);

    @Select("SELECT userId FROM tbl_review WHERE moduleId = #{moduleId}")
    public long findManagerId(long moduleId);

    @Select("SELECT * FROM tbl_shenhe WHERE moduleId = #{moduleId} AND recoreId = #{recoreId}")
    public List<Shenhe> findShenhe(int moduleId,Long recoreId);

    @Update("UPDATE tbl_shenhe SET shenHeTime=#{shenHeTime},shenHeResult=#{shenHeResult},memo=1 WHERE recoreId =#{recoreId} AND moduleId=#{moduleId} AND memo=0;")
    public Boolean tijiaoShenhe(Date shenHeTime , String shenHeResult , Long recoreId, int moduleId);
}
